package com.crm.service.impl.contactManager;

import com.crm.common.model.Enum.StatusCodeEnum;
import com.crm.common.util.CommonUtils;
import com.crm.dao.mapper.contactManager.ContactErrorRecordMapper;
import com.crm.dao.mapper.contactManager.ContactExchangeCodeMapper;
import com.crm.dao.mapper.contactManager.ContactMapper;
import com.crm.dao.mapper.customMapper.contactManagerCustomMapper.ContactCustomMapper;
import com.crm.dao.mapper.systemManager.SysParameterSettingMapper;
import com.crm.model.entity.contactManager.*;
import com.crm.model.entity.sys.UserAccount;
import com.crm.model.entity.systemManager.SysParameterSetting;
import com.crm.model.entity.systemManager.SysParameterSettingExample;
import com.crm.model.qo.contactManager.ContactFollowPlanTimeQO;
import com.crm.model.qo.contactManager.ContactQO;
import com.crm.model.vo.contactManager.*;
import com.crm.service.contactManager.ContactDbService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 联系人管理信息
 */
@Service
public class ContactDbServiceImpl implements ContactDbService {
    @Autowired
    private ContactMapper contactMapper;

    @Autowired
    ContactCustomMapper contactCustomMapper;

    @Autowired
    ContactErrorRecordMapper contactErrorRecordMapper;

    @Autowired
    ContactExchangeCodeMapper contactExchangeCodeMapper;

    @Autowired
    SysParameterSettingMapper sysParameterSettingMapper;

    /**
     * 联系人管理信息--超级管理员
     * @param contactQO 查询条件
     * @param sortOrder 排序字段,类型
     * @return
     */
    @Override
    public List<ContactVO> selectContactGlyList(ContactQO contactQO,Integer dateUnit, String sortOrder) {
        return contactCustomMapper.selectContactGlyList(contactQO, dateUnit, sortOrder);
    }

    /**
     * 联系人管理信息--分公司管理员
     * @param contactQO 查询条件
     * @param sortOrder 排序字段,类型
     * @return
     */
    @Override
    public List<ContactVO> selectContactFgsList(ContactQO contactQO,Integer dateUnit, String sortOrder) {
        return contactCustomMapper.selectContactFgsList(contactQO, dateUnit, sortOrder);
    }

    /**
     * 联系人管理信息--普通用户
     * @param contactQO 查询条件
     * @param sortOrder 排序字段,类型
     * @return
     */
    @Override
    public List<ContactVO> selectContactPtyhList(ContactQO contactQO,Integer dateUnit, String sortOrder) {
        return contactCustomMapper.selectContactPtyhList(contactQO, dateUnit, sortOrder);
    }

    /**
     * 客户详情-新增联系人-名字重复问题   联系人管理表
     * @param customerId  客户id
     * @param contactName 联系人名称
     * @param contactInformation 联系方式
     * @param contactNature 联系人性质  0企业联系人  1个人联系人
     * @param accountId 用户id
     * @return
     */
    @Override
    public List<Contact> getCustomerIdAndContactNameAndAccountId(String customerId, String contactName,String contactInformation,String contactNature,String accountId) {
        UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();
        ContactExample contactExample = new ContactExample();
        ContactExample.Criteria criteria = contactExample.createCriteria();

        criteria.andContactNameEqualTo(contactName);
        criteria.andContactNatureEqualTo(Integer.parseInt(contactNature));
        criteria.andAccountIdEqualTo(accountId);
        criteria.andCustomerIdEqualTo(customerId);
        criteria.andContactInformationEqualTo(contactInformation);
        criteria.andCompanyIdEqualTo(userAccount.getCompanyId());
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<Contact> list = contactMapper.selectByExample(contactExample);
        return list;
    }

    /**
     * 修改联系人管理表
     * @param contact 联系人实体
     * @return
     */
    @Override
    public boolean updateContact(Contact contact) {
        Boolean result = false;
        int num = contactMapper.updateByPrimaryKeySelective(contact);
        if(num>0){
            result = true;
        }
        return result;
    }

    /**
     * 联系人-新增联系人
     * @param contact 联系人实体
     * @return
     */
    @Override
    public Boolean addContact(Contact contact) {
        Boolean result = false;
        int num = contactMapper.insertSelective(contact);
        if(num>0){
            result = true;
        }
        return result;
    }

    /**
     * 修改联系人废止状态
     * @param contact 联系人实体
     * @return
     */
    @Override
    public Boolean updateAbolishStateById(Contact contact) {
        return contactMapper.updateByPrimaryKeySelective(contact) > 0;
    }

    /**
     * 联系人-删除  逻辑删除
     * @param contact 联系人实体
     * @return
     */
    @Override
    public Boolean deleteContactById(Contact contact) {
        return contactMapper.updateByPrimaryKeySelective(contact) > 0;
    }

    /**
     * 查询联系人--mybatis查询
     * @param contactId 联系人id
     * @return
     */
    @Override
    public Contact selectContactById(String contactId) {
        return contactMapper.selectByPrimaryKey(contactId);
    }

    @Override
    public Contact selectContactByExample(ContactExample contactExample) {
        List<Contact> contactList = contactMapper.selectByExample(contactExample);
        if(contactList != null && contactList.size() > 0){
            return contactMapper.selectByExample(contactExample).get(0);
        }
        return null;
    }

    /**
     * 通过联系人id查询联系人详细信息
     * @param contactId 联系人id
     * @return
     */
    @Override
    public ContactVO selectContactDetailById(String contactId) {
        return contactCustomMapper.selectContactDetailById(contactId);
    }

    /**
     * 商机-新增商机-通过客户id查询联系人列表
     * @param customerId 客户id
     * @return
     */
    @Override
    public List<Contact> contactByCustomerIdList(String customerId) {
        UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();
        ContactExample contactExample = new ContactExample();
        ContactExample.Criteria criteria = contactExample.createCriteria();
        criteria.andCustomerIdEqualTo(customerId);
        criteria.andAccountIdEqualTo(userAccount.getAccountId());
        criteria.andCompanyIdEqualTo(userAccount.getCompanyId());
        //废止状态 已启动
        criteria.andAbolishStateEqualTo(1);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<Contact> list = contactMapper.selectByExample(contactExample);
        return list;
    }

    /**
     * 根据联系人名称和联系方式判重，是否插入联系人管理
     * @Author pym
     * @Date  2021/3/4 14:58
     * @param contactName --联系人姓名
     * @param contactInformation --联系方式
     * @return {@link {java.lang.Boolean}}
     */
    @Override
    public Boolean isInsertContact(String contactName, String contactInformation) {
        UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();
        Boolean result = false;
        ContactExample contactExample = new ContactExample();
        ContactExample.Criteria criteria = contactExample.createCriteria();
        criteria.andContactNameEqualTo(contactName);
        criteria.andContactInformationEqualTo(contactInformation);
        criteria.andAccountIdEqualTo(userAccount.getAccountId());
        criteria.andCompanyIdEqualTo(userAccount.getCompanyId());
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<Contact> contacts = contactMapper.selectByExample(contactExample);
        if (contacts.size() > 0) {
            result = true;
        }
        return result;
    }

    /**
     * 联系人-新增联系人--同一客户下联系人重名-->合并联系方式
     * @param customerId 客户id
     * @param contactName 联系人姓名
     * @param contactNature  联系人性质  0企业联系人  1非企业联系人
     * @return
     */
    @Override
    public List<Contact> getContactName(String customerId, String contactName, String contactNature, String accountId) {
        UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();
        ContactExample contactExample = new ContactExample();
        ContactExample.Criteria criteria = contactExample.createCriteria();
        criteria.andCustomerIdEqualTo(customerId);
        criteria.andContactNameEqualTo(contactName);
        criteria.andAccountIdEqualTo(accountId);
        //criteria.andContactNatureEqualTo(Integer.parseInt(contactNature));
        //废止状态 已启动
        criteria.andAbolishStateEqualTo(1);
        criteria.andCompanyIdEqualTo(userAccount.getCompanyId());
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<Contact> list = contactMapper.selectByExample(contactExample);
        return list;
    }

    /**
     * 联系人-客户详情-联系人列表-跳转联系人详情
     * @param customerId 客户id
     * @param contactInformation 联系方式
     * @param contactName  联系人姓名
     * @return
     */
    @Override
    public Contact getContactId(String customerId, String contactInformation, String contactName) {
        ContactExample contactExample = new ContactExample();
        ContactExample.Criteria criteria = contactExample.createCriteria();
        criteria.andCustomerIdEqualTo(customerId);
        criteria.andContactInformationEqualTo(contactInformation);
        criteria.andContactNameEqualTo(contactName);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<Contact> list = contactMapper.selectByExample(contactExample);
        if(list.size() == 0){
            return new Contact();
        }else{
            return list.get(0);
        }

    }

    /**
     * 商机-新增商机-过客户id查询联系人列表  分页
     * @param customerId 客户id
     * @param order 分组
     * @return
     */
    @Override
    public List<Contact> pageContactByCustomerIdList(String customerId, String order) {
        UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();
        ContactExample contactExample = new ContactExample();
        ContactExample.Criteria criteria = contactExample.createCriteria();
        contactExample.setOrderByClause(order);
        criteria.andCustomerIdEqualTo(customerId);
        //废止状态 已启动
        criteria.andAbolishStateEqualTo(1);
        criteria.andCompanyIdEqualTo(userAccount.getCompanyId());
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<Contact> list = contactMapper.selectByExample(contactExample);
        return list;
    }

    /**
     * 查询联系人里面有的行业
     * @param name 登录人
     * @param number 0超管 1普通管理员  2普通用户
     * @return
     */
    @Override
    public List<IndustryAreaVO> selectIndustry(String name,Integer number) {
        return contactCustomMapper.selectIndustry(name,number);
    }

    /**
     * 查询联系人里面有的地图
     * @param name 登录人
     * @param number 0超管 1普通管理员  2普通用户
     * @return
     */
    @Override
    public List<IndustryAreaVO> selectProvince(String name, Integer number) {
        return contactCustomMapper.selectProvince(name,number);
    }

    /**
     * 根据客户ID更新联系人所有人ID、分公司ID
     * @Author pym
     * @Date  2021/4/8 15:51
     * @param customerId -客户ID
     * @param accountId -用户ID
     * @param companyId -公司ID
     * @param updatePeopleId -更新人ID
     * @param updateTm -更新时间
     * @return {@link {java.lang.Boolean}}
     */
    @Override
    public Boolean updateContactByCustomerId(String customerId, String accountId, String companyId,
                                             String updatePeopleId, Date updateTm) {
        return contactCustomMapper.updateContactByCustomerId(customerId,accountId,companyId,updatePeopleId,updateTm) > 0;
    }


    @Override
    public List<ContactStatisticsVO> statisticsNewContactByDay(String startTime, String endTime,
                                                               String accountId) {
        return contactCustomMapper.statisticsNewContactByDay(startTime, endTime,accountId);
    }

    @Override
    public List<ContactStatisticsVO> statisticsNewContactByMonth(int thisYear,String accountId) {
        return contactCustomMapper.statisticsNewContactByMonth(thisYear,accountId);
    }

    /**
     * 根据客户ID和联系方式查询联系人信息
     * @Author pym
     * @Date  2021/5/10 14:41
     * @param customerId 客户ID
     * @param contactInformation 联系方式
     * @return {@link {com.crm.model.entity.contactManager.Contact}}
     */
    public Contact getContact(String customerId, String contactInformation) {
        ContactExample contactExample = new ContactExample();
        ContactExample.Criteria criteria = contactExample.createCriteria();
        criteria.andCustomerIdEqualTo(customerId);
        criteria.andContactInformationEqualTo(contactInformation);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<Contact> list = contactMapper.selectByExample(contactExample);
        if(list != null && list.size() > 0){
            return list.get(0);
        }
        return null;
    }

    /**
     * 根据客户id、姓名、手机号查询有没有这个联系人
     * @param customerId
     * @param contactPerson
     * @param contactPersonPhone
     * @return
     */
    @Override
    public ContactVO isInsertContactPerson(String customerId, String contactPerson, String contactPersonPhone) {
        return contactCustomMapper.isInsertContactPerson(customerId,contactPerson,contactPersonPhone);
    }

    /**
     * 新增个人客户根据手机号查询联系人是否存在
     * @Author pym
     * @Date  2021/6/11 9:24
     * @param contactInformation 联系方式
     * @return {@link {com.crm.model.entity.contactManager.Contact}}
     */
    public Boolean getContactByContactInformation(String contactInformation) {
        ContactExample contactExample = new ContactExample();
        ContactExample.Criteria criteria = contactExample.createCriteria();
        criteria.andContactInformationEqualTo(contactInformation);
        criteria.andContactNatureEqualTo(1);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        return contactMapper.selectByExample(contactExample).size() > 0;
    }

    /**
     * 呼叫中心根据手机号和账号Id查询联系人
     * @Author pym
     * @Date  2021/6/11 14:44
     * @param contactInformation 联系方式
     * @param accountId 账号Id
     * @return {@link {com.crm.model.entity.contactManager.Contact}}
     */
    public Contact getContactByContactInfoAndId(String contactInformation, String accountId) {
        ContactExample contactExample = new ContactExample();
        ContactExample.Criteria criteria = contactExample.createCriteria();
        criteria.andContactInformationEqualTo(contactInformation);
        criteria.andAccountIdEqualTo(accountId);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        contactExample.setOrderByClause("contact_nature is null,contact_nature");//企业联系人排在前面
        List<Contact> list = contactMapper.selectByExample(contactExample);
        if(list != null && list.size() > 0){
            return list.get(0);
        }
        return null;
    }

    /***
     * 根据客户id、联系人姓名查询联系人信息
     * @param customerId 客户id
     * @param contactName 联系人姓名
     * @Author: luojie
     * @Date: 2021/6/15 9:46
     */
    public Contact getContactByCustomerIdAndContactName(String customerId, String contactName) {
        ContactExample contactExample = new ContactExample();
        ContactExample.Criteria criteria = contactExample.createCriteria();
        criteria.andCustomerIdEqualTo(customerId);
        criteria.andContactNameEqualTo(contactName);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<Contact> list = contactMapper.selectByExample(contactExample);
        if(list.size() == 0){
            return new Contact();
        }else{
            return list.get(0);
        }

    }

    /**
     * 客户详情-新增联系人-名字重复问题   联系人管理表
     * @param customerId  客户id
     * @param contactName 联系人名称
     * @param contactInformation 联系方式
     * @param contactNature 联系人性质  0企业联系人  1个人联系人
     * @param accountId 用户id
     * @return
     */
    @Override
    public List<Contact> getCustomerIdAndContactNameAndAccountIdAndCompanyId(String customerId, String contactName,String contactInformation,String contactNature,String accountId,String companyId,String csd) {
        UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();
        boolean rs = CommonUtils.isAdmin(userAccount.getUserId());
        ContactExample contactExample = new ContactExample();
        ContactExample.Criteria criteria = contactExample.createCriteria();

        criteria.andContactNameEqualTo(contactName);
        criteria.andContactNatureEqualTo(Integer.parseInt(contactNature));

        //客服部都可以看
        if(!rs&&!"csd".equals(csd)) {
            criteria.andAccountIdEqualTo(accountId);
            criteria.andCompanyIdEqualTo(companyId);
        }


        //联系人性质  0企业联系人  1非企业联系人
        //if(!StringUtils.isBlank(customerId)){
        //}
        //企业联系人查询客户id
        if("0".equals(contactNature)) {
            criteria.andCustomerIdEqualTo(customerId);
        }



        criteria.andAbolishStateEqualTo(1);

        criteria.andContactInformationEqualTo(contactInformation);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<Contact> list = contactMapper.selectByExample(contactExample);
        return list;
    }

    /**
     * 客户详情-新增联系人-名字重复问题   联系人管理表
     * @param customerId  客户id
     * @param contactName 联系人名称
     * @param contactInformation 联系方式
     * @param contactNature 联系人性质  0企业联系人  1个人联系人
     * @param accountId 用户id
     * @return
     */
    @Override
    public List<Contact> getCustomerIdAndContactNameAndAccountIdAndCompanyIds(String customerId, String contactName,String contactInformation,String contactNature,String accountId,String companyId) {
        ContactExample contactExample = new ContactExample();
        ContactExample.Criteria criteria = contactExample.createCriteria();

        criteria.andContactNameEqualTo(contactName);
        criteria.andContactNatureEqualTo(Integer.parseInt(contactNature));
        criteria.andAccountIdEqualTo(accountId);
        criteria.andCompanyIdEqualTo(companyId);
        //联系人性质  0企业联系人  1非企业联系人
        criteria.andCustomerIdEqualTo(customerId);

        criteria.andContactInformationEqualTo(contactInformation);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<Contact> list = contactMapper.selectByExample(contactExample);
        return list;
    }

    /**
     *新增联系人导入错误记录
     * @param contactErrorRecord
     * @return
     */
    @Override
    public Boolean insertContactErrorRecord(ContactErrorRecord contactErrorRecord) {
        Boolean result = false;
        int num = contactErrorRecordMapper.insertSelective(contactErrorRecord);
        if(num>0){
            result = true;
        }
        return result;
    }

    @Override
    public List<Contact> selectMyContactsByContactId(String contactId, String accountId, String companyId) {
        ContactExample contactExample = new ContactExample();
        ContactExample.Criteria criteria = contactExample.createCriteria();
        criteria.andContactIdEqualTo(contactId);
        criteria.andAccountIdEqualTo(accountId);
        criteria.andCompanyIdEqualTo(companyId);
        List<Contact> contacts = contactMapper.selectByExample(contactExample);
        return contacts;
    }

    @Override
    public List<Contact> selectMyContactsByCustomerId(String customerId, String accountId, String companyId) {
        ContactExample contactExample = new ContactExample();
        ContactExample.Criteria criteria = contactExample.createCriteria();
        criteria.andCustomerIdEqualTo(customerId);
        criteria.andAccountIdEqualTo(accountId);
        criteria.andCompanyIdEqualTo(companyId);
        List<Contact> contacts = contactMapper.selectByExample(contactExample);
        return contacts;
    }

    /**
     * 根据公司id查询联系人
     * @param companyId 公司id
     * @return
     */
    @Override
    public List<Contact> selectCompanyId(String companyId,int contactNature) {
        ContactExample contactExample = new ContactExample();
        ContactExample.Criteria criteria = contactExample.createCriteria();
        criteria.andCompanyIdEqualTo(companyId);
        criteria.andContactNatureEqualTo(contactNature);
        List<Contact> contacts = contactMapper.selectByExample(contactExample);
        return contacts;
    }

    /**
     * 根据公司id和联系人性质 企业联系人
     * @param companyId 客户id
     * @return
     */
    @Override
    public List<ContactRepeatVO> selectContactrepeat(String companyId) {
        return contactCustomMapper.selectContactrepeat(companyId);
    }


    /**
     * 客户导入判断联系人是否存在
     * @Author pym
     * @Date  2021/7/2 15:00
     * @param customerId 客户Id
     * @param contactInformation 联系方式
     * @param contactName 联系人姓名
     * @param contactNature 联系人性质
     * @return {@link {com.crm.model.entity.contactManager.Contact}}
     */
    @Override
    public Contact isContactRepeat(String customerId, String contactInformation, String contactName, Integer contactNature) {
        ContactExample contactExample = new ContactExample();
        ContactExample.Criteria criteria = contactExample.createCriteria();
        criteria.andCustomerIdEqualTo(customerId);
        criteria.andContactInformationEqualTo(contactInformation);
        criteria.andContactNameEqualTo(contactName);
        criteria.andContactNatureEqualTo(contactNature);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<Contact> list = contactMapper.selectByExample(contactExample);
        if(list.size() > 0){
            return list.get(0);
        }
        return null;
    }

    /**
     * 获取客户对应的联系人
     * @Author pym
     * @Date  2021/8/5 16:25
     * @param customerId 客户Id
     * @return {@link {java.util.List<com.crm.model.entity.contactManager.Contact>}}
     */
    @Override
    public List<Contact> getContactByCustomerId(String customerId) {
        ContactExample contactExample = new ContactExample();
        ContactExample.Criteria criteria = contactExample.createCriteria();
        criteria.andCustomerIdEqualTo(customerId);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<Contact> list = contactMapper.selectByExample(contactExample);
        return list;
    }

    /**
     * 新增联系人兑换码
     * @param contactExchangeCode 兑换码
     */
    @Override
    public Boolean addContactExchangeCode(ContactExchangeCode contactExchangeCode) {
        Boolean result = false;
        int num = contactExchangeCodeMapper.insertSelective(contactExchangeCode);
        if(num>0){
            result = true;
        }
        return result;
    }

    /**
     * 查询系统设置
     * @return
     */
    @Override
    public SysParameterSetting selectContactCodeStatus() {
        SysParameterSettingExample sysParameterSettingExample = new SysParameterSettingExample();
        SysParameterSettingExample.Criteria criteria = sysParameterSettingExample.createCriteria();
        criteria.andDeleteStatusEqualTo(0);
        List<SysParameterSetting> list = sysParameterSettingMapper.selectByExample(sysParameterSettingExample);
        if(list != null && list.size() > 0){
            return list.get(0);
        }else{
            return null;
        }
    }

    /**
     * 兑换码列表
     * @param contactId 联系人id
     * @param order 分组
     * @return
     */
    @Override
    public List<ContactExchangeCodeVO> selectContactExchangeCodeList(String contactId, String order) {
        /*ContactExchangeCodeExample contactExchangeCodeExample = new ContactExchangeCodeExample();
        contactExchangeCodeExample.setOrderByClause(order);
        ContactExchangeCodeExample.Criteria criteria = contactExchangeCodeExample.createCriteria();
        criteria.andContactIdEqualTo(contactId);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));*/
        //List<ContactExchangeCode> list = ;
        return contactCustomMapper.selectContactExchangeCodeList(contactId,order);
    }

    /**
     * 开启关闭联系人发码
     * @param sysParameterSetting 联系人发码状态  0发码 1不发码
     * @return
     */
    @Override
    public Boolean updateContactcodeStatus(SysParameterSetting sysParameterSetting) {
        Boolean result = false;
        int num = sysParameterSettingMapper.updateByPrimaryKeySelective(sysParameterSetting);
        if(num>0){
            result = true;
        }
        return result;
    }

    /**
     * 通过联系方式和兑换码查询
     * @param contactInformation 联系方式
     * @param code 兑换码
     * @return
     */
    @Override
    public ContactExchangeCode selectContactExchangeCodeByInformationAndCode(String contactInformation, String code) {
        ContactExchangeCodeExample contactExchangeCodeExample = new ContactExchangeCodeExample();
        ContactExchangeCodeExample.Criteria criteria = contactExchangeCodeExample.createCriteria();
        criteria.andContactInformationEqualTo(contactInformation);
        criteria.andExchangeCodeEqualTo(code);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<ContactExchangeCode> list = contactExchangeCodeMapper.selectByExample(contactExchangeCodeExample);
        if(list != null && list.size() > 0){
            return list.get(0);
        }else{
            return null;
        }
    }

    @Override
    public Integer checkExist(String customerId, String contactPhone) {
        ContactExample contactExample = new ContactExample();
        ContactExample.Criteria criteria = contactExample.createCriteria();
        criteria.andCustomerIdEqualTo(customerId);
        criteria.andContactInformationEqualTo(contactPhone);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<Contact> list = contactMapper.selectByExample(contactExample);
        return list.size();
    }

    /**
     * 查询联系人里面有的标签
     * @param name
     * @param number 0 超管 1普管 2普通
     * @return
     */
    @Override
    public List<String> selectTag(String name, Integer number) {
        return contactCustomMapper.selectTag(name,number);
    }

    /**
     * 新增跟进计划时间
     * @param qo
     * @return
     */
    @Override
    public Boolean addContactFollowPlanTimes(ContactFollowPlanTimeQO qo) {
        return contactCustomMapper.addContactFollowPlanTimes(qo);
    }

    /**
     * 查询客户下的其他联系人
     * @param customerId   客户Id
     * @return
     */
    @Override
    public List<Contact> selectOtherContactByCustomerId(String customerId, String contactId,String accountId,String companyId) {
        return contactCustomMapper.selectOtherContactByCustomerId(customerId,contactId,accountId,companyId);
    }

    /**
     * 修改跟进计划时间
     */
    @Override
    public List<Contact> selectLessDayFollowPlanTime(String date) {
        return contactCustomMapper.selectLessDayFollowPlanTime(date);
    }

    /**
     * 跟进计划时间清空
     * @param contact
     * @return
     */
    @Override
    public Boolean updateContactFollowPlanTime(Contact contact) {
        return contactCustomMapper.updateContactFollowPlanTime(contact);
    }

}
